package financial.sharing.center.receivable.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import financial.sharing.center.common.enums.ResponseContext;
import financial.sharing.center.common.utils.PageSize;
import financial.sharing.center.common.utils.R;
import financial.sharing.center.receivable.model.entity.ReceivableAccrued;
import financial.sharing.center.receivable.service.ReceivableAccruedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Map;

/**
 * @ClassName ReceivableAccruedController
 * @Description TODO
 * @Author guoyuhang
 * @ @csdn https://blog.csdn.net/qq_40788718
 * @Date 2021/5/15
 * @Version 1.0
 */
@RestController
@RequestMapping(value = "/receivable/receivable/accrued")
public class ReceivableAccruedController {

    @Autowired
    private ReceivableAccruedService receivableAccruedServiceImpl;

    @PostMapping(value = "get/all/receivable/accrued")
    public R getAllReceivableAccrued(Integer contractId,
                                     Integer accruedId,
                                     Integer currentPage){
        PageHelper.startPage(currentPage, PageSize.PAGESIZE_TEN);
        PageInfo<ReceivableAccrued> result = this.receivableAccruedServiceImpl.getAllReceivableAccrued(contractId,accruedId);
        return R.ok(result);
    }

    @PostMapping(value = "create/one/receivable/accrued")
    public R createOneReceivableAccrued(BigDecimal settlementAmount){
        Integer result = this.receivableAccruedServiceImpl.createOneReceivableAccrued(settlementAmount);
        return R.ok(ResponseContext.int2Enum(result).getName());
    }

    @PostMapping(value = "compile/one/receivable/accrued")
    public R compileOneReceivableAccrued(@RequestBody ReceivableAccrued receivableAccrued){
        Integer result = this.receivableAccruedServiceImpl.compileOneReceivableAccrued(receivableAccrued);
        return R.ok(ResponseContext.int2Enum(result).getName());
    }

    @PostMapping(value = "delete/one/receivable/accrued")
    public R deleteOneReceivableAccrued(Integer id){
        Integer result = this.receivableAccruedServiceImpl.deleteOneReceivableAccrued(id);
        return R.ok(ResponseContext.int2Enum(result).getName());
    }

    @PostMapping(value = "get/map/receivable/accrued")
    public Map<Integer,BigDecimal> getMapReceivableAccrued(){
        return this.receivableAccruedServiceImpl.getMapReceivableAccrued();
    }

}
